<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<body class="childrenBody">
<form class="layui-row changePwd" style="padding: 20px 20px 10px 20px;background-color: #fff;">
	<div class="layui-col-xs12 layui-col-sm6 layui-col-md6">

		<div class="layui-form-item" style="display: none">
			<label class="layui-form-label">用户名</label>
			<div class="layui-input-block">
				<input id="id" type="text" disabled class="layui-input layui-disabled">
			</div>
		</div>
		
		<div class="layui-form-item">
			<label class="layui-form-label">用户名</label>
			<div class="layui-input-block">
				<input id="usernameId" type="text"  disabled class="layui-input layui-disabled">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">旧密码</label>
			<div class="layui-input-block">
				<input id="oldPwdId" type="password" value="" placeholder="请输入旧密码" lay-verify="required|oldPwd" class="layui-input pwd">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">新密码</label>
			<div class="layui-input-block">
				<input id="newPwdId" type="password" value="" placeholder="请输入新密码" lay-verify="required|newPwd" id="oldPwd" class="layui-input pwd">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">确认密码</label>
			<div class="layui-input-block">
				<input id="newPwdSureId" type="password" value="" placeholder="请确认密码" lay-verify="required|confirmPwd" class="layui-input pwd">
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-input-block">
				<button class="layui-btn" lay-submit="" lay-filter="modify" >立即修改</button>
			</div>
		</div>
	</div>
</form>
</body>
<script>
	$(document).ready(function () {
		$.ajax({
			url: "user/getLoginUser",
			success: function (result) {
				if(0==result.code) {
					$("#id")[0].value = result.data.id;
					$("#usernameId")[0].value = result.data.username;
				}
			}
		});

	});
	layui.use(['form', 'layer'], function () {

		$ = layui.jquery;
		var form = layui.form,
				layer = layui.layer;
		form.on('submit(modify)', function (data) {
			var id = $("#id")[0].value;
			var username = $("#usernameId")[0].value;
			var oldPwd = $("#oldPwdId")[0].value;
			var newPwd = $("#newPwdId")[0].value;
			var newPwdSure = $("#newPwdSureId")[0].value;
			debugger;
			if(newPwd==oldPwd){
				layer.msg("新密码与旧密码重复",{icon: 5, time: 1000});
				return false;
			}
			if(newPwd!=newPwdSure){
				layer.msg("两次新密码不一致",{icon: 5, time: 1000});
				return false;
			}

			$.ajax({
				url:"/user/modifyPassword",
				data:{id:id,oldPwd:oldPwd,newPwd:newPwd,username:username},
				success:function (result) {
					if(0==result.code){
						layer.msg(result.msg,{icon: 1, time: 1000});
					}else{
						layer.msg(result.msg,{icon: 5, time: 1000});
					}
				}
			});
			return false;
		});
	});




</script>
